<?php

namespace LowCode\Core;

use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;


/**
 * @method static Builder table(string $name)
 */
class DB
{

    public static DB $instance;
    private Manager $manager;
    private Connection $connect;

    public function __construct()
    {
        $this->manager = new DM();
        $this->connect = $this->manager->getConnection();
    }

    public function getConnection(): Connection
    {
        return $this->connect;
    }

    public static function connection(): Connection
    {
        if (!isset(self::$instance) || !(self::$instance instanceof self)) {
            self::$instance = new self();
        }
        return self::$instance->getConnection();
    }


    public static function __callStatic($method, $parameters)
    {
        return self::connection()->$method(...$parameters);
    }

}
